package com.shendu.task.bo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import com.shendu.task.domain.DepartDoc;
/**
 * 部门表
 * @author unsky
 *
 */
@Component
public class DepartBo {

	@Autowired
	private MongoTemplate mongo;

	public void save(DepartDoc depart) {
		mongo.save(depart);

	}

	public DepartDoc getByNo(String no) {
		Criteria criteria = new Criteria();
		criteria.and("no").is(no);
		Query query = new Query(criteria);
		return  mongo.findOne(query, DepartDoc.class);
	}

	public void updateDepart(DepartDoc depart) {
		Criteria criteria = new Criteria();
		criteria.and("no").is(depart.getNo());
		Query query = new Query(criteria);
		Update update = new Update();
		update.set("userCount", depart.getUserCount());
		mongo.updateFirst(query, update, DepartDoc.class);
	}

	public List<DepartDoc> list(DepartDoc depart) {
		Criteria criteria = new Criteria();
		Query query = new Query(criteria);
		return mongo.find(query, DepartDoc.class);
	}

}
